import Vue from 'vue/dist/vue.js'
import App from './App'
import router from './router'
import store from './store/'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css';
//import Vuetify from 'vuetify'
import 'babel-polyfill'
import 'url-search-params-polyfill'

import { getRequest, postRequest, putRequest, deleteRequest, uploadFileRequest,postRequest2 } from '@/utils/api';
import {setStore,getStore,removeStore} from '@/utils/storage'
import utils    from '@/utils/util'

Vue.prototype.$utils=utils


Vue.config.productionTip = false
Vue.prototype.pression=true //权限是否开启

Vue.use(ElementUI);
//Vue.use(Vuetify);
Vue.prototype.getRequest = getRequest;
Vue.prototype.postRequest = postRequest;
Vue.prototype.putRequest = putRequest;
Vue.prototype.deleteRequest = deleteRequest;
Vue.prototype.uploadFileRequest = uploadFileRequest;


/**
 * 获取字典属性和值
 * @param params 包含dictCode的对象
 * @returns {Promise<any[]>}
 */
export const getSysDictItemList = data => postRequest('/sysDict/getSelectListByDictCode', data);
Vue.prototype.getSysDictItem = async function (dictCode) {
    /*const loading = this.$loading({
        lock: true,
        text: '加载中...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
    });*/
    var params = {
        dictCode: dictCode
    }
    let reply = await getSysDictItemList(params);
    /*loading.close();*/
    if (reply.code == 500) {
        this.$notify.error({
            title: '错误',
            message: reply.msg
        });
    } else {
        var arry = reply.data;
        var reulst = new Array();
        for(var i = 0; i < arry.length; i++) {
            reulst.push({
                name: arry[i].name,
                value: arry[i].value
            });
        }
        return reulst;
    }
};
/**
 * 获取sql字典表
 * @param data
 * @returns {*}
 */
export const getSysSqlList = data => postRequest('/sysDict/getSelectListBySqlCode', data);
Vue.prototype.getSysSql = async function (sqlCode) {
    /*const loading = this.$loading({
        lock: true,
        text: '加载中...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
    });*/
    var params = {
        sqlCode: sqlCode
    }
    let reply = await getSysSqlList(params);
    /*loading.close();*/
    if (reply.code == 500) {
        this.$notify.error({
            title: '错误',
            message: reply.msg
        });
    } else {
        var arry = reply.data;
        var reulst = new Array();
        for(var i = 0; i < arry.length; i++) {
            reulst.push({
                name: arry[i].name == undefined ? arry[i].NAME : arry[i].name,
                value: arry[i].value == undefined ? arry[i].VALUE : arry[i].value
            });
        }
        return reulst;
    }
};

/**
 * 测试vue跳转
 * //String staffId, String operateTime, String gsReportTradeId,String signmsg,String href
 */
export const getUserInfo = data => postRequest2('/user/isPression', data);
Vue.prototype.getUser=async function (staffId,operateTime,gsReportTradeId,signmsg,href){
    let param = new URLSearchParams();
    param.append("staffId", staffId);
    param.append("operateTime", operateTime);
    param.append("gsReportTradeId", gsReportTradeId);
    param.append("signmsg", signmsg);
    param.append("href", href);
    let reply = await getUserInfo(param);

    if (reply.code == 500) {
        this.$notify.error({
            title: '错误',
            message: reply.msg
        });
    } else {
        setStore("userId",staffId);
        return reply;
    }

};
new Vue({
    el: '#app',
    router,
    store,
    template: '<App/>',
    components: {App}
})